#include <iostream>
#include <mysql/mysql.h>
#include <boost/algorithm/string.hpp>
#include"db.hpp"
#include "util.hpp"
#include "online.hpp"
const std::string &host = "39.107.56.202";
int16_t port = 3306;
const std::string &username = "liuzhi";
const std::string &passwd = "liuzhi781010";
const std::string &dbname = "gobang";

void mysql_test()
{
    MYSQL *mysql = mysql_util::mysql_create(host, username, passwd, dbname, port);
    const char *sql = "insert into stu values('小明',16);";
    bool ret = mysql_util::mysql_exec(mysql, sql);
    if (ret == false)
    {
        return;
    }
    mysql_util::mysql_destory(mysql);
}
void json_test()
{
    Json::Value in_value;
    in_value["name"] = "刘若轩";
    in_value["age"] = 18;
    std::string out_string;
    json_util::serialize(in_value, &out_string);
    std::cout << out_string << std::endl;

    std::string in_string = R"({ "address" : "beijing", "fav" : "足球" })";
    Json::Value out_value;
    json_util::unserialize(in_string, &out_value);
    std::string address = out_value["address"].asString();
    std::string fav = out_value["fav"].asString();
    std::cout << address << " " << fav << std::endl;
}
void string_test()
{
    std::string str="2025/9/21";
    std::string year;
    std::string month;
    std::string day;
    std::vector<std::string> tokens;
    string_util::strsplit(tokens,str,"/",true);
    if(tokens.size()!=3)
    {
        std::cout<<"string split error :"<<str<<std::endl;
        return;
    }
    year=tokens[0];
    month=tokens[1];
    day=tokens[2];
    std::cout<<"年:"<<year<<" 月:"<<month<<" 日:"<<day<<std::endl;
}
void file_test()
{
    std::string filename="file.txt";
    std::string body;
    file_util::readfile(filename,&body);
    std::cout<<body<<std::endl;
}
void db_test()
{
    user_table user(host,username,passwd,dbname,port);
    Json::Value people;
    // people["username"]="刘智";
    // people["password"]="123465";
    user.lose(1);
    std::string out_string;
    json_util::serialize(people,&out_string);
    std::cout<<out_string<<std::endl;
}

void online_test()
{
    online_manager onm;
    wwserver_t conn();
    onm.enter_hall_user(2,conn);
    if(!onm.is_exist_hall(2))
    {
        std::cout<<"hall中不存在uid为2的用户"<<std::endl;
    }
    onm.erase(2);
        if(!onm.is_exist_hall(2))
    {
        std::cout<<"hall中不存在uid为2的用户"<<std::endl;
    }
}
int main()
{
    db_test();
    return 0;
}